package com.example.yichuangyun.mvvm.ui.activity.view;

import android.util.ArrayMap;

import androidx.lifecycle.MutableLiveData;

import com.example.yichuangyun.config.Constant;
import com.example.yichuangyun.model.contacts.AddressDataModel;
import com.example.yichuangyun.mvvm.base.BaseViewModel;
import com.example.yichuangyun.mvvm.di.retrofit.BaseModel;
import com.example.yichuangyun.mvvm.di.retrofit.BaseNetCallback;
import com.google.gson.Gson;

import java.util.Map;

public class SearchAddressBookViewModel extends BaseViewModel {

    public final MutableLiveData<String> keyWords = new MutableLiveData<>();

    public final MutableLiveData<AddressDataModel> contactsData = new MutableLiveData<>();

    /**
     * 获取联系人列表
     */
    public void getContactsList(int page, String keyWords, int type) {
        Map<String, Object> map = new ArrayMap<>();
        map.put("keywords", keyWords);
        map.put("examine", type);
        map.put("site", 0);
        map.put("page", page);
        map.put("pageSize", Constant.pageSize);
        addSubscribe(mRetrofitHelper.getContactsList(new Gson().toJson(map)).subscribeWith(new BaseNetCallback<AddressDataModel>() {

            @Override
            public void onSuccess(BaseModel<AddressDataModel> baseModel) {
                if (Constant.SUCCESS == baseModel.getCode()) {
                    contactsData.setValue(baseModel.getData());
                }
            }
        }));
    }
}
